#include<iostream>

using namespace std;

int main()
{
	int M, N, K, L, D;
	int x1, y1, x2, y2;
	int length[1000] = { 0 }, width[1000] = { 0 };
	int used_length[1000] = { 0 }, used_width[1000] = { 0 };
	cin >> M >> N >> K >> L >> D;
	for (int i = 0; i < D; i++)
	{
		cin >> x1 >> y1 >> x2 >> y2;
		if (x1 == x2) 
		{
			y1 < y2 ? width[y1]++ : width[y2]++;
			continue;
		}
		if (y1 == y2) 
		{
			x1 < x2 ? length[x1]++ : length[x2]++;
		}
	}
	for (int i = 0; i < K; i++)
	{
		int max = -1, index = -1;
		for (int j = 0; j < 1000; j++)
		{
			if (max < length[j])
			{
				max = length[j];
				index = j;
			}
		}
		used_length[index] = 1;
		length[index] = 0;
	}
	for (int i = 0; i < 1000; i++)
	{
		if (used_length[i] == 1) cout << i << " ";
	}
	cout << endl;
	for (int i = 0; i < L; i++)
	{
		int max = -1, index = -1;
		for (int j = 0; j < 1000; j++)
		{
			if (max < width[j])
			{
				max = width[j];
				index = j;
			}
		}
		used_width[index] = 1;
		width[index] = 0;
	}
	for (int i = 0; i < 1000; i++)
	{
		if (used_width[i] == 1) cout << i << " ";
	}
	return 0;
}